﻿using System;
using System.Collections.Generic;
using System.Text;
using Catalina.Common;
using System.Data;
using System.Collections.ObjectModel;
using System.Data.SqlClient;

namespace Catalina.Dal
{
	class CatalinaLabelReader : SqlReaderBase<CatalinaLabel>
	{
		private string startDate;

		public CatalinaLabelReader(String connectionString, String startDate) 
			: base(connectionString) 
		{
			this.startDate = startDate;
		}

		protected override string CommandText
		{
			get
			{
				return
					@"SELECT 
						cat.*, 
						prods.description, 
						prods.locAisle, 
						prods.locBlock, 
						prods.locSeq
					from
					(
						SELECT
							*
						FROM
							POSplus_catalina_signs
						WHERE
							start_date = @startDate
					) cat
					inner join
						POSplus_TagLoc_Products prods
					on
						cat.upc = prods.upc
					order by 
						isnull(locAisle, 999999), 
						locBlock, 
						locSeq, 
						cat.upc";
			}
		}

		protected override System.Data.CommandType CommandType
		{
			get { return System.Data.CommandType.Text; }
		}

		protected override System.Collections.ObjectModel.Collection<System.Data.IDataParameter> GetParameters(System.Data.IDbCommand command)
		{
			Collection<IDataParameter> parameters = new Collection<IDataParameter>();
		
			SqlParameter param = new SqlParameter("@startDate", startDate);
			parameters.Add(param);

			return parameters;
		}

		protected override MapperBase<CatalinaLabel> GetMapper()
		{
			return new CatalinaLabelMapper();			
		}
	}
}
